import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express'
import { DocumentBuilder } from '@nestjs/swagger';
import { SwaggerModule } from '@nestjs/swagger/dist';
import { AppModule } from './app.module';
import Validate from './common/validate';
import { TransformInterceptor } from './interceptor/transform.interceptor';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  const bodyParser = require('body-parser');
  require('body-parser-xml')(bodyParser);
  const options = new DocumentBuilder().setTitle('接口文档').setDescription('接口文档').setVersion('1').build()
  const document = SwaggerModule.createDocument(app, options)
  SwaggerModule.setup('/docs', app, document)
  app.useGlobalPipes(new Validate())
  app.use(bodyParser.xml());
  app.useGlobalInterceptors(new TransformInterceptor())
  app.setGlobalPrefix('api')
  app.useStaticAssets('uploads', { prefix: '/uploads' })
  app.useStaticAssets('files', { prefix: '/files' })
  await app.listen(3000);

}
bootstrap();
